package com.bishe.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bishe.pojo.Comment;
import com.bishe.service.CommentService;
import com.bishe.util.EcoBootException;
import com.bishe.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lwx
 * @since 2022-04-14
 */
@RestController
@CrossOrigin
@Api(tags = "评论控制器")
@RequestMapping("/comment")
public class CommentController {

    @Resource
    private CommentService commentService;

    @ApiOperation("所有评论")
    @GetMapping("/list")
    public Result getCommentList(){
        List<Comment> comments = commentService.getComments();
        return Result.ok(comments);
    }

    @ApiOperation("添加评论")
    @PostMapping("/add")
    public Result addComment(@RequestBody Comment comment){
        if (StrUtil.isEmpty(comment.getText().trim())){
            throw new EcoBootException("请输入内容");
        }
        commentService.addComment(comment);

        return Result.ok();
    }

}

